SHELL := /bin/bash

#定义变量指定生成的静态库和动态库的名字
#CUR_PWD = `pwd`
LIBNAME = mylib

#定义一个变量指定库文件的头文件的安装路径
INST_PATH = `pwd`/../install
LIBS_PATH = ${INST_PATH}/libs
INC_PATH = ${INST_PATH}/include

#定义编译器，如果今后交叉编译，只需在此处改成交叉编译器
CC=gcc
AR=ar

#目标
all: static_lib
	#echo "CUR_PWD: $CUR_PWD"
	#echo "LIBNAME: $LIBNAME"
	@make clear
	@make install

#dynameic_lib 目标来编译生成动态库
#dynameic_lib:
#	${CC} -shared -fPIC *.c -o lib${LIBNAME}.so -I${SQLPATH}include -L${SQLPATH}lib -lsqlite3

#static_lib 目标来编译生成静态库
static_lib:
	${CC} -I ${INC_PATH} -c *.c
	${AR} -rcs lib${LIBNAME}.a *.o

#install 目标来将编译生成的库文件和头文件拷贝到相应的安装路径下
install:
	mkdir -p ${INST_PATH}/{include,libs}
	cp -rf lib${LIBNAME}.* ${LIBS_PATH}
	cp -rf *.h ${INC_PATH}

#uninstall 目标来在安装路径下删除之前安装的库文件和头文件
uninstall:
	rm -f ${LIBS_PATH}/lib${LIBNAME}.*
	rm -f ${INC_PATH}/*.h
	
#clear 目标来将编译生成的object临时文件删除
clear:
	rm -f *.o

#clean 目标先通过clear删除所有的object临时文件，之后再删除编译产生的库文件
clean: clear
	rm -f lib${LIBNAME}.*

